package com.chushouya.order.service.admin.impl;

import com.chushouya.common.shunfeng.dto.SfCreateOrderDTO;
import com.general.framework.core.lang.Beans;
import com.general.framework.core.lang.Dates;
import com.chushouya.order.constants.LogisticsTypeEnum;
import com.chushouya.order.dao.entity.OrderLogisticsEntity;
import com.chushouya.order.dao.repository.OrderLogisticsRepository;
import com.chushouya.order.dto.admin.orderlogistics.OrderLogisticsDTO;
import com.chushouya.order.dto.admin.orderlogistics.OrderLogisticsQuery;
import com.chushouya.order.service.admin.OrderLogisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderLogisticsServiceImpl implements OrderLogisticsService {

    @Resource
    private OrderLogisticsRepository orderLogisticsRepository;

    @Override
    public OrderLogisticsDTO logistics(OrderLogisticsQuery query) {
        return null;
    }

    @Override
    public List<OrderLogisticsDTO> logisticsList(OrderLogisticsQuery query) {
        List<OrderLogisticsEntity> logisticsList = orderLogisticsRepository.selectList(query);
        return Beans.copyList(logisticsList, OrderLogisticsDTO.class);
    }

    @Override
    public void saveOrderLogistics(SfCreateOrderDTO sfCreateOrderDTO, Long orderId, Integer type) {
        OrderLogisticsEntity orderLogisticsEntity = new OrderLogisticsEntity();
        orderLogisticsEntity.setOrderId(orderId);
        orderLogisticsEntity.setType(type != null ? type : LogisticsTypeEnum.USER_SEND.value());
        orderLogisticsEntity.setExpressNo(sfCreateOrderDTO.getExpressNo());
        orderLogisticsEntity.setExpressCompany("顺丰速运");
        orderLogisticsEntity.setOrderCode(sfCreateOrderDTO.getSfOrderId());
        orderLogisticsEntity.setCreateTime(Dates.getTimeNow());
        orderLogisticsEntity.setUpdateTime(Dates.getTimeNow());
        orderLogisticsRepository.insertSelective(orderLogisticsEntity);
    }
}
